/**
 * 
 */
package br.com.ctm.advogadope.model;

import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlRootElement;

import br.com.ctm.advogadope.model.Tribunal.TipoJuizo;
import br.com.framework.persistencia.model.AuditedEntity;

/**
 * @author Cleber
 *
 */
@Entity
@Table(name = "PROCESSO", uniqueConstraints = {
		@UniqueConstraint(columnNames = {"npu", "tribunal", "tipoJuizo"}, name = "uk_processo_npu_tribunal_tipojuizo")
})
@XmlRootElement
public class Processo extends AuditedEntity {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String npu;
	
	private Tribunal tribunal;
	
	private TipoJuizo tipoJuizo;
	
	private String xmlProcessoJudicial;
	
	private Date dataAtualizacao;
	
	/**
	 * 
	 */
	public Processo() {
	}
	
	@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ_PROCESSO")
	@SequenceGenerator(name="SEQ_PROCESSO", sequenceName="SEQ_PROCESSO", allocationSize=1, initialValue=0)
	@Column(name = "ID_PROCESSO")
	@XmlID
	public Long getId() {
		return super.getId();
	}
	
	/**
	 * @return the npu
	 */
	@Column(name = "NPU", length = 255, nullable = false)
	@NotNull(message = "{processo.npu.obrigatorio}")
	@Pattern(regexp = "\\d{13}[1-9]{1}[0-9]{2}\\d{4}", message = "{processo.npu.invalido}")
	public String getNpu() {
		return npu;
	}

	/**
	 * @param npu the login to set
	 */
	public void setNpu(String nome) {
		this.npu = nome;
	}
	
	/**
	 * @return the uf
	 */
	@ManyToOne(targetEntity = Tribunal.class, optional = false)
	@JoinColumn(name="ID_TRIBUNAL", nullable = false)
	@XmlIDREF
	public Tribunal getTribunal() {
		return tribunal;
	}

	public void setTribunal(Tribunal tribunal) {
		this.tribunal = tribunal;
	}

	@Enumerated(EnumType.STRING)
	@Column(name = "TIPO_JUIZO", nullable = false)
	@NotNull(message = "{processo.tipoJuizo.obrigatorio}")
	public TipoJuizo getTipoJuizo() {
		return tipoJuizo;
	}

	public void setTipoJuizo(TipoJuizo tipoJuizo) {
		this.tipoJuizo = tipoJuizo;
	}

	@Lob
	@Basic(fetch = FetchType.LAZY)
	@Column(name = "XML_PROCESSO_PJE", nullable = true)
	public String getXmlProcessoJudicial() {
		return xmlProcessoJudicial;
	}

	public void setXmlProcessoJudicial(String xmlProcessoJudicial) {
		this.xmlProcessoJudicial = xmlProcessoJudicial;
	}

	@Column(name = "DATA_ATUALIZACAO_PJE", nullable = true)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getDataAtualizacao() {
		return dataAtualizacao;
	}

	public void setDataAtualizacao(Date dataAtualizacao) {
		this.dataAtualizacao = dataAtualizacao;
	}
	
	public static void main(String[] args) {
		//0000466-38.2011.8.17.8124
		System.out.println("Valido: " + "00004663820118178124".matches("\\d{13}[1-9]{1}[0-9]{2}\\d{4}"));
	}

}
